package com.qkjia.day03;

import java.util.concurrent.Callable;
import java.util.concurrent.FutureTask;

class MyRunnable implements  Runnable{

    @Override
    public void run() {
        System.out.println("MyRunnable is running");
    }
}
class MyCallable implements Callable<String>{

    @Override
    public String call() throws Exception {
        System.out.println(Thread.currentThread().getName()+"MyCallable is running");
//        SleepUtils.second(5);
        return "0720";
    }
}


public class Test03_Callable {
    public static void main(String[] args) throws Exception {
        //new Thread(new MyRunnable()).start();
        FutureTask<String> myTask = new FutureTask<>(new MyCallable());
//        new Thread(myTask).start();
//        //是一个阻塞的方法
//        String value = myTask.get();
//        System.out.println(value);

        new Thread(myTask,"zhangsan").start();
        new Thread(myTask,"lisi").start();
        //计算结果被复用
        System.out.println(myTask.get());
        System.out.println(myTask.get());
    }
}
